import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';

export default (appInfo: EggAppInfo) => {
  const config = {} as PowerPartial<EggAppConfig>;

  // override config from framework / plugin
  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1713251804893_2284';

  // 启动端口
  config.cluster = {
    listen: {
      path: '',
      port: 7002,
      hostname: '',
    },
  };

  // 密码加密设置
  config.crypto = {
    secret: 'DLwvMqPbROTl',
  };
  // sequelize配置
  config.sequelize = {
    datasources: [
      {
        dialect: 'mssql',
        host: '10.16.3.52',
        username: 'cncpro',
        password: 'lytech.2024',
        port: 1433,
        database: 'CNCPRO_QC',
        // 中国时区
        timezone: '+08:00',
        define: {
          // 取消数据表名复数
          freezeTableName: true,
          // 自动写入时间戳 created_at updated_at
          timestamps: true,
          createdAt: 'created_at',
          updatedAt: 'updated_at',
          // 所有驼峰命名格式化
          underscored: true,
        },
      },
      // {
      //   dialect: 'mssql',
      //   delegate: 'model2',
      //   dialectOptions: {
      //     encrypt: false,
      //   },
      //   host: '192.168.3.52',
      //   username: 'cncpro',
      //   password: 'cncpro',
      //   port: 1433,
      //   database: 'CNCPROCommon',
      //   // 中国时区
      //   timezone: '+08:00',
      // },
    ],
  };

  config.security = {
    csrf: {
      enable: false,
      ignoreJSON: true,
    },
    domainWhiteList: [
      'http://10.0.8.27',
      'http://localhost:8080',
    ],
  };
  config.cors = {
    origin: '*', // 匹配规则  域名+端口  *则为全匹配
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',
  };
  // 登录token
  config.jwt = {
    secret: 'DLwvMqPbROTl',
    // expiresIn: '1d',
  };

  // add your egg config in here
  config.middleware = [];

  // multipart 配置
  config.multipart = {
    fileSize: '5mb', // 文件大小限制
    mode: 'file', // 文件上传方式，file 或 stream
  };

  const bizConfig = {
    tokenName: 'X-Token',
    query: {
      pageSize: 10,
    },
  };

  // the return config will combines to EggAppConfig
  return {
    ...config,
    ...bizConfig,
  };
};
